<template>
  <div class="my_inf">
    <div class="inf_left">
      <div class="inf_photo">
        <img src="../../assets/img/logo.png" alt="" />
        <span>{{ myInf.s_name }}</span>
      </div>
      <ul class="clear">
        <li>
          年级：<span>{{ myInf.s_grade }}</span>
        </li>
        <li>
          学号：<span>{{ myInf.s_shoolId }}</span>
        </li>
        <li>
          专业：<span>{{ myInf.s_major }}</span>
        </li>
        <li>
          班级：<span>{{ myInf.s_classname }}</span>
        </li>
        <li>
          电话：<span>{{ myInf.s_phone }}</span>
        </li>
        <li>
          邮箱：<span>{{ myInf.s_eMail }}</span>
        </li>
      </ul>
      <div class="inf_btn">
        <el-button size="small" type="primary" @click="openamendInf()" round
          >修改信息</el-button
        >
      </div>
    </div>
    <div class="inf_right">
      <div>
        <h3>获得奖项</h3>
        <div class="null" v-if="awards.length == 0">暂无奖项</div>
        <ul class="awards_list" v-if="awards.length > 0">
          <li v-for="infor in awards" :key="infor.a_id">
            <h4>{{ infor.a_title }}</h4>
            <span class="delbtn">{{ infor.a_time }}</span>
            <el-popconfirm
              title="确定要删除奖项吗？"
              @confirm="delAward(infor.a_id)"
            >
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="small "
                slot="reference"
                circle
              ></el-button>
            </el-popconfirm>
          </li>
        </ul>
        <div class="addBtn click" @click="openamendAward">添加新奖项</div>
      </div>
      <div>
        <h3>所属团队</h3>
        <div class="team_card" v-if="JSON.stringify(team) !== '{}'">
          <h3>团队成员</h3>
          <div>
            <span>队长： </span>
            <div @click="lookStusentInf(team.cap_id)" class="click">
              <img src="../../assets/img/logo.png" alt="" />
              <span>{{ team.cap }}</span>
            </div>
            <span>队员：</span>
            <div
              v-for="(member, i) in team.t_member"
              :key="i"
              @click="lookStudentInf(member.s_id)"
              class="click"
            >
              <img src="../../assets/img/logo.png" alt="" />
              <span>{{ member.s_name }}</span>
            </div>
          </div>
        </div>
        <div class="team_card" v-if="JSON.stringify(team) === '{}'">暂未加入队伍</div>
      </div>
      <div>
        <h3>我的项目</h3>
        <el-collapse v-if="project.length > 0">
          <el-collapse-item
            v-for="(data, i) in project"
            :key="data.id"
            :title="data.p_title"
            :name="i"
          >
            <div>
              {{ data.p_synopsis }}
            </div>
            <el-button
            v-if="data.p_type == 2"
              class="downBtn"
              size="small"
              type="primary"
              round
              ><a class="downBtna">已完结</a></el-button
            >
            <el-button
            v-if="data.p_type == 1"
              class="downBtn"
              size="small"
              type="success"
              round
              ><a  class="downBtna" >进行中...</a></el-button
            >
          </el-collapse-item>
        </el-collapse>
        <div v-if="project.length == 0">暂无项目</div>
      </div>
    </div>
    <el-dialog title="修改信息" :visible.sync="dialogFormVisible">
      <ul class="tc_mes">
        <li>姓名：<input type="text" v-model="myInf.s_name" /></li>
        <li>学号：<input type="text" v-model="myInf.s_shoolId" /></li>
        <li>专业：<input type="text" v-model="myInf.s_major" /></li>
        <li>班级：<input type="text" v-model="myInf.s_classname" /></li>
        <li>电话：<input type="text" v-model="myInf.s_phone" /></li>
        <li>邮件：<input type="text" v-model="myInf.s_eMail" /></li>
      </ul>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelamendInf">取 消</el-button>
        <el-button type="primary" @click="amendInf">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="修改信息" :visible.sync="adddAwardialogFormVisible">
      <ul class="tc_mes">
        <li>奖项名称：<input type="text" v-model="addAward.a_title" /></li>
        <li>
          获取时间：<input
            type="text"
            v-model="addAward.a_time"
            placeholder="时间格式2022-02-24"
          />
        </li>
      </ul>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelamendAward">取 消</el-button>
        <el-button type="primary" @click="amendAward">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      student_id:'',
      myInf: {},
      awards: [],
      project: [],
      team: [],
      addAward: {
        a_title: "",
        a_time: "",
        a_type: 1,
      },
      dialogFormVisible: false,
      adddAwardialogFormVisible: false,
    };
  },
  name: "StudentInf",
  mounted() {
    this.student_id = this.$route.query.student_id;
    this.getStudentData();
  },
  methods: {
    getStudentData() {
      axios
        .post(`http://localhost:3000/student/studentMes`, {
          s_id: this.student_id,
        })
        .then((ret) => {
          this.project = ret.data.studentMes.project;
          this.myInf = ret.data.studentMes.mes;
          this.awards = ret.data.studentMes.awards;
          this.team = ret.data.studentMes.team;
        });
    },
    cancelamendInf() {
      this.dialogFormVisible = false;
    },
    openamendInf() {
      this.dialogFormVisible = true;
    },
    cancelamendAward() {
      this.adddAwardialogFormVisible = false;
    },
    openamendAward() {
      this.adddAwardialogFormVisible = true;
    },
    amendInf() {
      axios
        .post(`http://localhost:3000/updateStudent`, {
          studentData: this.myInf,
        })
        .then((ret) => {
          if (ret.data.code == 1) {
            this.$message({
              showClose: true,
              message: "修改成功",
              type: "success",
            });
            this.cancelamendInf();
          }
        });
    },
    amendAward() {
      if (this.addAward.a_title == "" || this.addAward.a_time == "") {
        this.$message({
          showClose: true,
          message: "有未填项！！！",
          type: "warning",
        });
      } else {
        axios
          .post(`http://localhost:3000/addAward`, {
            addAwardData: this.addAward,
            user_id: this.myInf.s_id,
          })
          .then((ret) => {
            if (ret.data.code == 1) {
              this.$message({
                showClose: true,
                message: "添加成功",
                type: "success",
              });
              this.cancelamendAward();
              this.getStudentData();
            }
          });
      }
    },
    delAward(id) {
      axios.post(`http://localhost:3000/delAward`, { a_id: id }).then((ret) => {
        if (ret.data.code == 1) {
          this.$message({
            showClose: true,
            message: "删除成功",
            type: "success",
          });
          this.cancelamendAward();
          this.getStudentData();
        }
      });
    },
    lookStudentInf(id) {
      var token = localStorage.getItem("token");
      var u_id = token.substring(1, token.length - 1).split("#")[1] * 1;
      if (id == u_id) {
        this.$router.push({ path: "/MyInf" });
      } else if (id !== this.leaveWordTo) {
        this.$router.push({ path: "/StudentInf", query: { student_id: id } });
        this.leaveWordTo = this.$route.query.student_id;
        this.getStudentData();
      } else return;
    },
  },
};
</script>

<style scoped>
.my_inf {
  display: flex;
  justify-content: space-around;
  padding: 10px 20px;
}
.inf_left {
  width: 300px;
  height: 700px;
  position: sticky;
  top: 10px;
  padding: 0px 10px;
}
.inf_left,
.inf_right > div {
  border-radius: 20px;
  border: 1px solid #ddd;
  background-color: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(5px);
  border-left: 2px solid rgba(255, 255, 255, 0.5);
  border-top: 2px solid rgba(255, 255, 255, 0.5);
}
.inf_photo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 20px auto;
  font-size: 18px;
  font-weight: 700;
  color: #303133;
}
.inf_photo > img {
  width: 50px;
  height: 50px;
  overflow: hidden;
  border-radius: 50%;
  border: 1px solid #ddd;
  border-left: 2px solid rgba(255, 255, 255, 0.5);
  border-top: 2px solid rgba(255, 255, 255, 0.5);
}
.inf_left > ul {
  border-top: 2px solid #606266;
  margin-bottom: 200px;
}
.inf_left > ul > li {
  font-size: 16px;
  color: #606266;
  margin: 20px 10px;
}
.inf_btn {
  display: flex;
  justify-content: space-between;
  margin: 20px 10px;
}
.inf_right {
  width: 70%;
}
.inf_right > div {
  margin-bottom: 20px;
  box-sizing: border-box;
  padding: 10px 20px;
}
.inf_right > div > h3 {
  width: 100px;
  height: 40px;
  font: 18px/40px "";
  font-weight: 700;
  color: #303133;
  text-align: center;
  border-bottom: 2px solid #606266;
}

.awards_list {
  display: flex;
  flex-wrap: wrap;
}
.awards_list li {
  width: 35%;
  margin: 20px;
  padding: 10px;
  color: white;
  background-color: #409eff;
  border-radius: 20px;
}
.team_card {
  border-radius: 10px;
  padding: 20px 10px;
}
.team_card img {
  background-color: #fff;
}
.team_card > h4 {
  height: 24px;
  font-weight: 700;
  font: 18px/24px "";
  margin-bottom: 20px;
}
.team_card > div {
  margin-top: 5px;
  height: 60px;
  display: flex;
  align-items: center;
}
.team_card > div > span {
  font-size: 18px;
  display: inline-block;
}
.team_card > div > div {
  display: inline-block;
  margin: 0 20px;
}
.delbtn {
  display: inline-block;
  width: 270px;
}
.downBtn{
margin: 10px;
float: right;
}
img {
  display: block;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 1px solid #ddd;
}
</style>
